package com.lmaos.allcontrol.beancontrol.utils_;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class StringUtils {
	public static boolean isBlank(String str){
		return str==null||str.trim().isEmpty();
	}
	public static String getString(Object... objs){
		StringBuilder sb = new StringBuilder();
		for (Object obj : objs) {
			sb.append(obj);
		}
		return sb.toString();
	}
	
	public final static char[] ABC = "ABCDEFGHIGKLMNOPQRSTUVWXYZ".toCharArray();
	public final static char[] NUM = "12345678900987654321".toCharArray();
	public final static char[] abc = "abcdefghigklmnopqrstuvwxyz".toCharArray();
	public final static char[] ABC123 = "12345678900987654321ABCDEFGHIGKLMNOPQRSTUVWXYZ".toCharArray();
	public final static char[] abc123 = "12345678900987654321abcdefghigklmnopqrstuvwxyz".toCharArray();
	public final static char[] ABCabc123 = "12345678900987654321ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz".toCharArray();
	public final static SimpleDateFormat yyyyMMddHH = new SimpleDateFormat("yyyyMMddHH");
	public final static SimpleDateFormat yyyyMMddHHmm = new SimpleDateFormat("yyyyMMddHHmm");
	public final static String ABC123_MOD = "ABC123";
	public final static String NUM_MOD = "NUM";
	public final static String abc123_MOD = "abc123";
	public final static String ABC_MOD = "ABC";
	public final static String abc_MOD = "abc";
	public static char[] getChars(String mod){
		if(ABC_MOD.equals(mod)){
			return ABC;
		}else if(NUM_MOD.equals(mod)){
			return NUM;
		}else if(abc123_MOD.equals(mod)){
			return abc123;
		}else if(ABC123_MOD.equals(mod)){
			return ABC123;
		}else if(abc_MOD.equals(mod)){
			return abc;
		}else{
			return ABCabc123;
		}
	}
	public static String random_str_date_h_32(String head,String mod){
		return random_str_date_h(head, mod, 32);
	}
	public static String random_str_date_h(String head,String mod,int maxlen){
		StringBuilder text = new StringBuilder(head);
		text.append(yyyyMMddHH.format(new Date(System.currentTimeMillis())));
		int len = maxlen-head.length()-10;
		if(len>0){
			text.append(random_str(getChars(mod),len));
		}
		return text.substring(0, maxlen);
	}
	
	public static String random_str_date_mi_32(String head,String mod){
		return random_str_date_mi(head, mod, 32);
	}
	public static String random_str_date_mi(String head,String mod,int maxlen){
		StringBuilder text = new StringBuilder(head);
		text.append(yyyyMMddHHmm.format(new Date(System.currentTimeMillis())));
		int len = maxlen-head.length()-10;
		if(len>0){
			text.append(random_str(getChars(mod),len));
		}
		return text.substring(0, maxlen);
	}
	
	public static String random_str_ABC(int len){
		int indexs[] = NumberUtils.toInts(0, ABC.length-1);
		indexs = NumberUtils.toRandom(indexs);
		int index = 0;
		StringBuilder text = new StringBuilder(len);
		for (int i = 0; i < len; i++) {
			text.append(ABC[indexs[index]]);
			index = NumberUtils.getNextIndex(index, indexs.length);
		}
		return random_str(ABC, len);
	}
	
	public static String random_str_ABC123(int len){
		return random_str(ABC123, len);
		
	}
	public static String random_str_abc123(int len){
		return random_str(abc123, len);
		
	}
	public static String random_str_NUM(int len){
		return random_str(NUM, len);
		
	}
	public static String random_str_ABCabc123(int len){
		return random_str(ABCabc123, len);
		
	}
	public static String random_str(char[] src,int len){
		Random r = new Random();
		int index = 0;
		StringBuilder text = new StringBuilder(len);
		for (int i = 0; i < len; i++) {
			index = r.nextInt(src.length);
			text.append(src[index]);
		}
		return text.toString();
		
	}
	public static void main(String[] args) {
		System.out.println(random_str_date_mi_32("Q123456_",abc123_MOD));
	}
}
